package pri.zxx.webdemo.config;

import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pri.zxx.webdemo.config.properties.SwaggerProperties;

/**
 * @author zxx
 * @desc autoconfig swagger
 * @createTime 2019-02-22-下午 12:52
 */
@EnableConfigurationProperties(value = SwaggerProperties.class)
@Configuration
@Slf4j
public class SwaggerAutoConfiguration {

	@Autowired
	private SwaggerProperties swaggerProperties;

	@Bean
	public OpenAPI openAPI() {
		log.info("----->>配置swagger");
		return new OpenAPI()
				.info(new Info()
						.title(swaggerProperties.getAppName() + ":服务接口文档")
						.description(swaggerProperties.getDesc())
						.version("v1"))
				.externalDocs(new ExternalDocumentation()
						.description("zxxTest")
						.url("http://" + swaggerProperties.getIpAddress() + ":" + swaggerProperties.getAppPort() + "/"));
	}

}
